-- @owner: @kyeleze
-- @date: 2022/5/16
-- @testpoint: 列存表不支持raw类型，隐含调用插入数据成功

--step1:建立自定义类型转换函数;expect:创建函数成功
create or replace function raw_to_int
(
    in raw
)
returns integer
as
$$
declare
begin
if $1 = (select hextoraw('a')) then
return 10;
end if;
return false;
end;
$$
language plpgsql;
/

--step2:创建转换关系;expect:创建转换关系成功
drop cast if exists (raw as integer) cascade;
drop cast if exists (abstime as reltime) cascade;
create cast(raw as integer) with function raw_to_int(raw) as implicit;
create cast(abstime as reltime) without function as implicit;


--step3:建列存表;expect:建表成功
drop table if exists t_create_cast_0071 cascade;
create table t_create_cast_0071(i integer, b reltime) with (orientation = column);

--step4:隐含调用插入数据;expect:插入数据成功
insert into t_create_cast_0071 values(hextoraw('a'), abstime '2022-05-13 16:05:05+08');
select * from t_create_cast_0071;

--step5:清理环境;expect:清理成功
drop cast if exists (raw as integer) cascade;
drop function if exists raw_to_int(raw) cascade;
drop table if exists t_create_cast_0071;
